package com.sgb.kjwl.view.ui.adapter.home;

import android.annotation.SuppressLint;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.sgb.kjwl.R;
import com.swgk.core.view.entity.MenuEntity;

import java.util.List;

public class CommodityConditionsAdapter extends RecyclerView.Adapter<CommodityConditionsAdapter.CommodityConditionsViewHolder>{
    Context context;
    List<MenuEntity> childList;
    int mposition;
    CommodityConditionsViewHolder mcommodityConditionsViewHolder;

    public CommodityConditionsAdapter(Context context, List<MenuEntity> childList) {
        this.context = context;
        this.childList = childList;
    }

    @NonNull
    @Override
    public CommodityConditionsViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View inflate = View.inflate(context, R.layout.adapter_commodity_conditions_itme, null);
        CommodityConditionsViewHolder commodityConditionsViewHolder = new CommodityConditionsViewHolder(inflate);
        return commodityConditionsViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull CommodityConditionsViewHolder commodityConditionsViewHolder, @SuppressLint("RecyclerView") int i) {
        mcommodityConditionsViewHolder=commodityConditionsViewHolder;
         commodityConditionsViewHolder.item_all.setText(childList.get(i).getName());
        if(i==mposition){
            commodityConditionsViewHolder.item_all.setTextColor(context.getResources().getColor(R.color.new_blue));
            commodityConditionsViewHolder.item_all_line.setVisibility(View.VISIBLE);
        }else {
            commodityConditionsViewHolder.item_all.setTextColor(context.getResources().getColor(R.color.color_333333));
            commodityConditionsViewHolder.item_all_line.setVisibility(View.GONE);
        }
        commodityConditionsViewHolder.item_all.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mposition=i;
                notifyDataSetChanged();
            }
        });
    }
    public void manualRefresh(int i){
        mposition=i;

        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        return childList.size();
    }

    public class CommodityConditionsViewHolder extends RecyclerView.ViewHolder {

        private  TextView item_all;
        private final TextView item_all_line;

        public CommodityConditionsViewHolder(@NonNull View itemView) {
            super(itemView);
            item_all = itemView.findViewById(R.id.item_all);
            item_all_line = itemView.findViewById(R.id.item_all_line);
        }
    }
//    public void addDatas(List<> newDatas) {
//        if (this.datas == null) {
//            this.datas = new ArrayList<>();
//        }
//        int last = datas.size();
//        this.datas.addAll(newDatas);
//        //      notifyItemInserted(last + 1);
//        notifyDataSetChanged();
//    }
}